package art.yulang.service.impl;

import art.yulang.annotation.Autowired;
import art.yulang.annotation.Service;
import art.yulang.annotation.Transactional;
import art.yulang.dao.AccountDao;
import art.yulang.pojo.Account;
import art.yulang.service.TransferService;

@Service("transferService")
@Transactional
public class TransferServiceImpl implements TransferService {
    @Autowired
    private AccountDao accountDao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
        int i = 1/0;
        accountDao.updateAccountByCardNo(from);
    }
}
